import { err } from '@/utils/uniapi';
export function img(arr: any) {
  if (arr) {
    arr.forEach((e: any) => {
      if (e.coverUrl) {
        e.coverUrl = JSON.parse(e.coverUrl);
      }
    });
  }
  return arr;
}
export function cartimg(arr: any) {
  arr.forEach((e: any) => {
    e.goodsBO.coverUrl = JSON.parse(e.goodsBO.coverUrl);
  });
  return arr;
}
export function sum(arr: any) {
  try {
    let sum_price = 0;
    let sum_count = 0;
    arr.forEach((e: any) => {
      sum_price += e.goodsBO.price * e.goodsCount;
      sum_count += e.goodsCount;
    });
    sum_price = Number(sum_price.toFixed(2));
    return {
      sum_price,
      sum_count
    };
  } catch (error) {
    err(error);
    throw error;
  }
}
export function unit(e: any) {
  var str = e.indexOf('水');
  if (str === -1) {
    e = '份';
  } else {
    e = '瓶';
  }
  return e;
}
export function time(e: any) {
  var time = Date.now();
  var etime = Date.parse(e);
  if (e === '') {
    e = '暂无活动';
  } else if (etime > time) {
    e = '未开始';
  } else if (etime <= time) {
    e = '查看详情';
  }
  return e;
}

export function ordersta(e: any) {
  switch (e) {
    case 'UNPAID':
      e = '待付款';
      break;
    case 'ACCOUNT_PAID':
      e = '已付款';
      break;
    case 'CANCEL':
      e = '已取消';
      break;
    case 'SUCCESS':
      e = '已完成';
      break;
    case 'DISABLED':
      e = '禁用';
      break;
    case 'NORMAL':
      e = '正常';
      break;
    case 'WX_PAY':
      e = '微信支付';
      break;
    case 'INTEGRAL_PAY':
      e = '积分支付';
      break;
    case 'CASH_PAY':
      e = '现金支付';
      break;
  }
  return e;
}
export function sta(e: any) {
  switch (e) {
    case 'DISABLED':
      e = '禁用';
      break;
    case 'NORMAL':
      e = '正常';
      break;
  }
  return e;
}
export function goodsta(e: any) {
  switch (e) {
    case 'DISABLED':
      e = '已下架';
      break;
    case 'NORMAL':
      e = '已上架';
      break;
  }
  return e;
}
export function billsta(e: any) {
  switch (e) {
    case 'WX_PAY':
      e = '微信支付';
      break;
    case 'POINT_RECHARGE':
      e = '积分充值';
      break;
    case 'INTEGRAL_PAY':
      e = '积分支付';
      break;
    case 'CASH_PAY':
      e = '现金支付';
      break;
    case 'RETURN_WX_ORDERS':
      e = '微信售后';
      break;
    case 'RETURN_PRESENT_ORDERS':
      e = '积分售后';
      break;
  }
  return e;
}
export function retsta(e: any) {
  switch (e) {
    case 'WX_PAY':
      e = '微信支付';
      break;
    case 'INTEGRAL_PAY':
      e = '积分支付';
      break;
    case 'CASH_PAY':
      e = '现金支付';
      break;
    case 'POINT_RECHARGE':
      e = '积分充值';
      break;
    case 'AWAITING_MODERATION':
      e = '等待商家审核';
      break;
    case 'PASS_AUDIT':
      e = '审核通过';
      break;
    case 'RETURN_SUCCESS':
      e = '售后完成';
      break;
    case 'CLOSE':
      e = '售后关闭';
      break;
  }
  return e;
}
export function hdsta(e: any) {
  switch (e) {
    case 'DISABLED':
      e = '已下架';
      break;
    case 'NORMAL':
      e = '已上架';
      break;
    case 'RATIO':
      e = '百分比';
      break;
    case 'RATION':
      e = '定量';
      break;
    case 'ORDERS_PAY':
      e = '消费';
      break;
    case 'RECHARGE':
      e = '充值';
      break;
  }
  return e;
}
